*******************************************************************************
* Panel A: East Baton Rouge
*******************************************************************************

clear

set obs 100

gen variable = ""
gen vintage = .
forvalues i = 1(1)10 {
	gen year`i' = ""
}

local i = 1

foreach variable in pctnhblack ncrime permits fairm {

	foreach year in 2000 2010 2020 {

		if "`variable'" == "pctnhblack" {
		
			replace vintage = `year' if _n == `i'
			replace variable = "`variable'" if _n == `i'
		
			preserve
			
				use "dataset_east_baton_rouge_cross", clear
				
				cor pctnhblack pctnhblack2000 if year == `year'
			
			restore
			
			replace year10 = string(r(rho), "%20.02fc") if _n == `i'
			
			local i = `i' + 1
			
		}
		
		if "`variable'" == "ncrime" {
		
			replace vintage = `year' if _n == `i'
			replace variable = "`variable'" if _n == `i'
		
			forvalues j = 1(1)9 {
			
			preserve
			
				use "dataset_east_baton_rouge_crime", clear
				
				keep if year_precinct == `year'
				encode precinct, gen(precinctid)
				drop if mi(precinct)
				drop precinct 
				
				xtset precinct year_crime
				cor ncrime l`j'.ncrime
									
			restore
			
			replace year`j' = string(r(rho), "%20.02fc") if ///
				_n == `i'
			
			}
			
			local i = `i' + 1
		
		}
		
		if "`variable'" == "permits" {
		
			replace vintage = `year' if _n == `i'
			replace variable = "`variable'" if _n == `i'
		
			forvalues j = 1(1)9 {
			
			preserve
			
				local f = "dataset_east_baton_rouge_" + ///
					"building_permits"
				use "`f'", clear
				
				keep if year_precinct == `year'
				encode precinct, gen(precinctid)
				drop if mi(precinct)
				drop precinct 
				
				xtset precinct year_permits				
				cor permits l`j'.permits
									
			restore
			
			replace year`j' = string(r(rho), "%20.02fc") if ///
				_n == `i'
			
			}
			
			local i = `i' + 1
		
		}
		
		if "`variable'" == "fairm" {
		
			replace vintage = `year' if _n == `i'
			replace variable = "`variable'" if _n == `i'
		
			forvalues j = 1(1)5 {
			
			preserve
			
				local f = "dataset_east_baton_rouge_" + ///
					"property_values"
				use "`f'", clear
				
				keep if year_precinct == `year'
				encode precinct, gen(precinctid)
				drop if mi(precinct)
				drop precinct 
				
				xtset precinct year_prop				
				cor fairm l`j'.fairm
									
			restore
			
			replace year`j' = string(r(rho), "%20.02fc") if ///
				_n == `i'
			
			}
			
			local i = `i' + 1
		
		}
		
	}
	
}

keep if !mi(variable)

replace variable = "Share Black" if variable == "pctnhblack"
replace variable = "Crimes" if variable == "ncrime"
replace variable = "Building permits" if variable == "permits"
replace variable = "Property values" if variable == "fairm"

#delimit;

listtex 
	using "_output/table A10 a.tex"
	,
		replace 
		type 
		rstyle(tabular) 	
		head(
			\begin{tabular*}{\hsize}{@{\hskip\tabcolsep
			\extracolsep\fill}l*{12}{l}}
			\toprule \underline{Variable} & \underline{Year} & 
			\multicolumn{9}{c}{\underline{Years Lagged}}  \\
			 &  & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
			\midrule
		)
		foot("\bottomrule\end{tabular*}")
		;
		
#delimit cr

*******************************************************************************
* Panel B: Fort Worth
*******************************************************************************

clear

set obs 100

gen variable = ""
gen vintage = .
forvalues i = 1(1)10 {
	gen year`i' = ""
}

local i = 1

foreach variable in pctnhblack ncrime fairm {

	foreach year in 2009 2014 2020 {

		if "`variable'" == "pctnhblack" {
		
			replace vintage = `year' if _n == `i'
			replace variable = "`variable'" if _n == `i'
		
			preserve
			
				use "dataset_fort_worth_cross", clear
				
				cor pctnhblack pctnhblack2000 if year == `year'
			
			restore
			
			replace year10 = string(r(rho), "%20.02fc") if _n == `i'
			
			local i = `i' + 1
			
		}
		
		if "`variable'" == "ncrime" {
		
			replace vintage = `year' if _n == `i'
			replace variable = "`variable'" if _n == `i'
		
			forvalues j = 1(1)2 {
			
			preserve
			
				use "dataset_fort_worth_crime", clear
				
				keep if year_precinct == `year'
				drop if mi(precinct)
				
				xtset precinct year_crime
				cor ncrime l`j'.ncrime
									
			restore
			
			replace year`j' = string(r(rho), "%20.02fc") if ///
				_n == `i'
			
			}
			
			local i = `i' + 1
		
		}
		
		if "`variable'" == "fairm" {
		
			replace vintage = `year' if _n == `i'
			replace variable = "`variable'" if _n == `i'
		
			forvalues j = 1(1)5 {
			
			preserve
			
				local f = "dataset_fort_worth_" + ///
					"property_values"
				use "`f'", clear
				
				keep if year_precinct == `year'
				drop if mi(precinct)
				
				xtset precinct year_prop				
				cor total_v l`j'.total_v
									
			restore
			
			replace year`j' = string(r(rho), "%20.02fc") if ///
				_n == `i'
			
			}
			
			local i = `i' + 1
		
		}
		
	}
	
}

keep if !mi(variable)

replace variable = "Share Black" if variable == "pctnhblack"
replace variable = "Crimes" if variable == "ncrime"
replace variable = "Building permits" if variable == "permits"
replace variable = "Property values" if variable == "fairm"

#delimit;

listtex 
	using "_output/table A10 b.tex"
	,
		replace 
		type 
		rstyle(tabular) 	
		head(
			\begin{tabular*}{\hsize}{@{\hskip\tabcolsep
			\extracolsep\fill}l*{12}{l}}
			\toprule \underline{Variable} & \underline{Year} & 
			\multicolumn{9}{c}{\underline{Years Lagged}}  \\
			 &  & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
			\midrule
		)
		foot("\bottomrule\end{tabular*}")
		;
		
#delimit cr

*******************************************************************************
* End
*******************************************************************************
